﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

using MECopter.Configuration;
using MECopter.Quadrocopter;

namespace MECopter.Configuration.Quadrocopter
{
    /// <summary>
    /// Interaktionslogik für SerialConfigUI.xaml
    /// </summary>
    public partial class QuadroConfigUI : Window
    {


        public QuadroConfigUI()
        {
            InitializeComponent();          
            LoadConfig();
        }

        private void LoadConfig()
        {
            tb_YawP.Text = QuadrocopterConfig.pidParameters.YawPGain.ToString();
            tb_YawI.Text = QuadrocopterConfig.pidParameters.YawIGain.ToString();
            tb_YawD.Text = QuadrocopterConfig.pidParameters.YawDGain.ToString();

            tb_PitchP.Text = QuadrocopterConfig.pidParameters.PitchPGain.ToString();
            tb_PitchI.Text = QuadrocopterConfig.pidParameters.PitchIGain.ToString();
            tb_PitchD.Text = QuadrocopterConfig.pidParameters.PitchDGain.ToString();

            tb_RollP.Text = QuadrocopterConfig.pidParameters.RollPGain.ToString();
            tb_RollI.Text = QuadrocopterConfig.pidParameters.RollIGain.ToString();
            tb_RollD.Text = QuadrocopterConfig.pidParameters.RollDGain.ToString();
        }

        private void btSavePID_Click(object sender, RoutedEventArgs e)
        {
            float[] yawGains = new float[3];
            yawGains[0] = (float)Convert.ToDouble(tb_YawP.Text);
            yawGains[1] = (float)Convert.ToDouble(tb_YawI.Text);
            yawGains[2] = (float)Convert.ToDouble(tb_YawD.Text);

            float[] pitchGains = new float[3];
            pitchGains[0] = (float)Convert.ToDouble(tb_PitchP.Text);
            pitchGains[1] = (float)Convert.ToDouble(tb_PitchI.Text);
            pitchGains[2] = (float)Convert.ToDouble(tb_PitchD.Text);

            float[] rollGains = new float[3];
            rollGains[0] = (float)Convert.ToDouble(tb_RollP.Text);
            rollGains[1] = (float)Convert.ToDouble(tb_RollI.Text);
            rollGains[2] = (float)Convert.ToDouble(tb_RollD.Text);

            QuadrocopterConfig.pidParameters.SetParameters(yawGains, pitchGains, rollGains);
            
        }

        private void btLoadPID_Click(object sender, RoutedEventArgs e)
        {
            LoadConfig();
        }
       
    }
}
